package com.ming.javaweb.util;

import java.sql.*;

public class JDBCUtil {
    private static final String URL = "jdbc:mysql://39.103.205.130:3306/studentweb?useUnicode=true&characterEncoding=utf-8&serverTimezone=CST";
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    private static final String USER_NAME = "studentWeb";
    private static final String PWD = "002582";

    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

     /**
     *
     * @return
     * @throws SQLException
     */
    public static Connection getConn() throws SQLException {
        return DriverManager.getConnection(URL,USER_NAME,PWD);
    }

    /**
     *
     * @param resultSet
     * @throws SQLException
     */
    public static void closeResultSet(ResultSet resultSet) throws SQLException {
        if (resultSet != null){
            resultSet.close();
        }
    }

    /**
     *
     * @param preparedStatement
     */
    public static void closePs(PreparedStatement preparedStatement) {
        try {
            if (preparedStatement != null){
                preparedStatement.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    /**
     *
     * @param connection
     */
    public static void closeConn(Connection connection) {
        try {
            if (connection != null){
                connection.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

//    public static void main(String[] args) throws SQLException {
//        System.out.println(JDBCutil.getConn());
//    }
//
}
